cc.Class({
  extends: cc.Component,

  properties: {
    id: 0,
    type: 0,
    hp: cc.Label,
    icon: cc.Sprite
  },

  // data: {id,iconSF,itemName,itemPrice}
  init(data) {
    this.id = data.id;
    this.type = data.type;
    // this.icon.spriteFrame = data.iconSF;
    this.hp.string = data.hp;

    let icon_res = [
      'element_blue_square',
      'element_green_square',
      'element_grey_square',
      'element_purple_square',
      'element_red_square',
      'element_yellow_square'
    ];

    let sprite_icon_res;

    if (this.type != 0) {
      // buff 进入
      this.hp.string = '';
      this.node.block_type = 'buff_1'; //给预制体分组
      sprite_icon_res = 'buff_langch';
    } else {
      // 普通砖块
      sprite_icon_res = icon_res[data.iconSF];
    }

    // 本地加载图片
    cc.loader.loadRes(
      sprite_icon_res,
      cc.SpriteFrame,
      function(err, ret) {
        if (err) {
          console.log(err);
          return;
        }
        this.icon.spriteFrame = ret;
      }.bind(this)
    );
  }
});
